package org.springblade.modules.admin.controller.openapi;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.service.BuildingService;
import org.springblade.modules.admin.service.ElevatorService;
import org.springblade.modules.admin.service.IMaintainPlanConfigService;
import org.springblade.modules.admin.service.IMaintainPlanContentService;
import org.springblade.modules.admin.vo.openapi.SidaBuildingBasicVO;
import org.springblade.modules.admin.vo.openapi.SidaElevatorBasicVO;
import org.springblade.modules.admin.vo.openapi.SidaElevatorSchedulesVO;
import org.springblade.modules.admin.vo.openapi.SidaMaintainPlanVO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * Sida 内部提供给算法团队的 API 接口
 * @author: Sharry
 * @createTime: 2024-09-26 14:40
 * @version: Version-1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/openapi/algorithm/data")
@Api(value = "内部算法数据接口", tags = "内部算法数据接口")
public class AlgorithmOpenAPIController {

	private final BuildingService buildingService;

	private final ElevatorService elevatorService;

	private final IMaintainPlanContentService maintainPlanContentService;

	private final IMaintainPlanConfigService maintainPlanConfigService;

	/**
	 * 根据租户id查询项目基础信息列表
	 */
	@TenantIgnore
	@GetMapping("/building/list")
	@ApiOperationSupport(order = 41)
	@ApiOperation(value = "根据租户id查询项目基础信息列表", notes = "根据租户id查询项目基础信息列表")
	public R<List<SidaBuildingBasicVO>> getBuildingListByTenantId(String tenantId) {
		return R.data(buildingService.getBuildingListByTenantId(tenantId));
	}

	/**
	 * 根据租户id查询电梯基础信息列表
	 */
	@TenantIgnore
	@GetMapping("/elevator/list")
	@ApiOperationSupport(order = 42)
	@ApiOperation(value = "根据租户id查询电梯基础信息列表", notes = "根据租户id查询电梯基础信息列表")
	public R<List<SidaElevatorBasicVO>> getElevatorListByTenantId(String tenantId) {
		return R.data(elevatorService.getElevatorListByTenantId(tenantId));
	}

	/**
	 * 根据租户id和时间区间查询保养工单列表
	 */
	@TenantIgnore
	@ApiOperationSupport(order = 43)
	@GetMapping("/maintain-plan/list")
	@ApiOperation(value = "根据租户id和时间区间查询保养工单列表", notes = "根据租户id和时间区间查询保养工单列表")
	public R<List<SidaMaintainPlanVO>> getMaintainPlanListByTenantIdAndTime(String tenantId, Date startTime, Date endTime) {
		if(Func.isNull(startTime) || Func.isNull(endTime)){
			throw new ServiceException("时间参数不能为空！");
		}
		return R.data(maintainPlanContentService.getMaintainPlanListByTenantIdAndTime(tenantId, startTime, endTime));
	}

	/**
	 * 根据租户id和时间区间查询电梯排期列表
	 */
	@TenantIgnore
	@ApiOperationSupport(order = 44)
	@GetMapping("/elevator-schedules/list")
	@ApiOperation(value = "根据租户id和时间区间查询电梯排期列表", notes = "根据租户id和时间区间查询电梯排期列表")
	public R<List<SidaElevatorSchedulesVO>> getElevatorSchedulesListByTenantIdAndTime(
		String tenantId,
		Date lastMaintainStartTime, Date lastMaintainEndTime,
		Date previousPlanDateStartTime, Date previousPlanDateEndTime,
		Date nextPlanDateStartTime, Date nextPlanDateEndTime,
		Date overdueDateStartTime, Date overdueDateEndTime
	) {
		return R.data(maintainPlanConfigService.getElevatorSchedulesListByTenantIdAndTime(
			tenantId,
			lastMaintainStartTime, lastMaintainEndTime,
			previousPlanDateStartTime, previousPlanDateEndTime,
			nextPlanDateStartTime, nextPlanDateEndTime,
			overdueDateStartTime, overdueDateEndTime
			));
	}

}
